package squareBorderPackage;

/**
 * A class of open borders involving two squares in two opposed directions.
 * 
 * @author	Jessa Bekker & Esther Alberts
 * @version	2.0
 */
public class OpenBorder extends Border {

	/**
	 * Initialize this new openBorder.
	 */
	public OpenBorder(Square square, Direction direction) {
		super(square, direction);
	}

	/**
	 * Return whether this openBorder is slippery or not.
	 */
	@Override
	public boolean getSlippery() {
		return false;
	}

	/**
	 * Return whether this wall is an obstacle or not.
	 * 
	 * @return result==false;
	 */
	@Override
	public boolean isObstacle() {
		return false;
	}

	/**
	 * @return This border if the other border is not effective | if (other ==
	 *         null) | then (result == this)
	 * @return This border if the other border is a open border. |if (other
	 *         instanceof OpenBorder) | then (result == this)
	 * @return The strongest border of the other border and this border in all
	 *         other cases. |if (! (other == null || | other instanceof
	 *         OpenBorder)) | then (result == other.getStrongestBorder(this)
	 */
	@Override
	public Border getStrongestBorder(Border other) {
		if (other == null)
			return this;
		if (other instanceof OpenBorder)
			return this;
		return other.getStrongestBorder(this);

	}
	
	/**
	 * Split this border in two borders.
	 * 
	 * @return	...
	 * 			| result[0].getSquareAt(getSquareDirections()[0]) = this.getSquareAt(getSquareDirections()[0])
	 * 			| && result[0].getSquareAt(getSquareDirections()[1]) = null
	 * 			| && result[1].getSquareAt(getSquareDirections()[1]) = this.getSquareAt(getSquareDirections()[0])
	 * 			| && result[1].getSquareAt(getSquareDirections()[0]) = null
	 */
	@Override
	public OpenBorder[] split() {
		Square square = getSquareAt(getSquareDirections()[0]);
		removeSquareAt(getSquareDirections()[0]);
		OpenBorder other = new OpenBorder(square, getSquareDirections()[0]);
		OpenBorder[] borders = new OpenBorder[2];
		borders[0] = other;
		borders[1] = this;
		return borders;
	}

}
